//
//  ViewController.swift
//  BWPanelKit
//
//  Created by 1906457616@qq.com on 01/28/2022.
//  Copyright (c) 2022 1906457616@qq.com. All rights reserved.
//

import UIKit
import BWPanelKit

class ViewController: UIViewController {
    var dialog: DialogVC?
    var slideFrom: DrawerVC.SlideFrom = .left
    var slideStop: DrawerVC.SlideStop = .topLeft

    func closeOuterDialog() {
        dialog?.close()
    }
    
    lazy var drawerVC: DrawerVC = {
        let v = UIView()
        v.backgroundColor = .red
        let vc = DrawerVC(panelView: v, panelSize: .init(width: 300, height: 200), slideFrom: slideFrom, slideStop: slideStop)
        return vc
    }()
    
    @IBAction func showDropDown(_ sender: UIControl) {
        let v = UIView()
        v.backgroundColor = .blue
        let vc = DropVC(panelView: v, contentHeight: 200)
        Pannel.show(vc)
    }
    
    @IBAction func showImagePopup(_ sender: UIControl) {
        let vc = ImagePopupVC(image: .init(named: "cover")!)
        vc.show()
    }
    
    @IBAction func sliderFromChanged(_ sender: UISegmentedControl) {
        switch sender.selectedSegmentIndex {
        case 0: slideFrom = .left
        case 1: slideFrom = .right
        case 2: slideFrom = .top
        case 3: slideFrom = .bottom
        case 4: slideFrom = .custom(point: .zero)
        default: break
        }
        
        drawerVC.slideFrom = slideFrom
        guard drawerVC.isShowing else {
            drawerVC.show()
            return
        }
        drawerVC.close { [weak self] in
            self?.drawerVC.show()
        }
    }
    
    @IBAction func sliderStopChanged(_ sender: UISegmentedControl) {
        let idx = sender.selectedSegmentIndex
        switch sender.tag {
        case 0:
            switch idx {
            case 0: slideStop = .topLeft
            case 1: slideStop = .topMiddle
            case 2: slideStop = .topRight
            default: break
            }
        case 1:
            switch idx {
            case 0: slideStop = .leftMiddle
            case 1: slideStop = .center
            case 2: slideStop = .rightMiddle
            case 3: slideStop = .custom(point: .init(x: 200, y: 200))
            default: break
            }
        case 2:
            switch idx {
            case 0: slideStop = .bottomLeft
            case 1: slideStop = .bottomMiddle
            case 2: slideStop = .bottomRight
            default: break
            }
        default:
            break
        }
        
        drawerVC.slideStop = slideStop
        guard drawerVC.isShowing else {
            drawerVC.show()
            return
        }
        drawerVC.close { [weak self] in
            self?.drawerVC.show()
        }
    }
    
    @IBAction func showRLMorePanel(_ sender: UIControl) {
        let vc = RLMoreActionsPannelVC(items: [
            .collect(id: "", title: ""),
            .block(isAdded: false, targetId: "", completion: nil),
            .delete(momentId: ""),
            .chat(userId: ""),
            .follow(userId: ""),
            .chat(userId: ""),
            .follow(userId: "")
        ])
        Pannel.show(vc)
    }
    
    @IBAction func showDialog(_ sender: UIControl) {
        dialog = Dialog.show(title: "Title", message: "MessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessage", actions: [
            .init(title: "Open new dialog", style: .default, closeable: false, handler: {
                Dialog.show(title: "Opened New Dialog", message: "Click `close` button will close the outer dialog", actions: [
                    .init(title: "Cancel", style: .cancel),
                    .init(title: "Close", style: .destructive, handler: { [weak self] in
                        self?.closeOuterDialog()
                    })
                ])
            }),
            .init(title: "Cancel", style: .cancel, closeable: true, handler: nil),
            .init(title: "Delete", style: .destructive, closeable: false, handler: nil),
            .init(title: "Success", style: .primary, closeable: true, handler: nil),
            .init(title: "Cancel", style: .cancel, closeable: true, handler: nil),
            .init(title: "Delete", style: .destructive, closeable: false, handler: nil),
            .init(title: "Success", style: .primary, closeable: true, handler: nil),
            .init(title: "Delete", style: .destructive, closeable: false, handler: nil),
            .init(title: "Success", style: .primary, closeable: true, handler: nil),
            .init(title: "Cancel", style: .cancel, closeable: true, handler: nil),
            .init(title: "Delete", style: .destructive, closeable: false, handler: nil),
            .init(title: "Success", style: .primary, closeable: true, handler: nil),
            .init(title: "Delete", style: .destructive, closeable: false, handler: nil),
            .init(title: "Success", style: .primary, closeable: true, handler: nil),
            .init(title: "Cancel", style: .cancel, closeable: true, handler: nil),
            .init(title: "Delete", style: .destructive, closeable: false, handler: nil),
            .init(title: "Success", style: .primary, closeable: true, handler: nil),
            .init(title: "Delete", style: .destructive, closeable: false, handler: nil),
            .init(title: "Success", style: .primary, closeable: true, handler: nil),
            .init(title: "Cancel", style: .cancel, closeable: true, handler: nil),
            .init(title: "Delete", style: .destructive, closeable: false, handler: nil),
            .init(title: "Success", style: .primary, closeable: true, handler: nil),
            .init(title: "Delete", style: .destructive, closeable: false, handler: nil),
            .init(title: "Success", style: .primary, closeable: true, handler: nil),
            .init(title: "Cancel", style: .cancel, closeable: true, handler: nil),
            .init(title: "Delete", style: .destructive, closeable: false, handler: nil),
            .init(title: "Success", style: .primary, closeable: true, handler: nil)
        ], maskViewCancellable: false, completion: nil)
    }
}

